<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
request.setAttribute("basePath", basePath);
request.setAttribute("basePath1", path);
%>
<html>
<link href="<%=path %>/static/js/plugs/bootstrap/css/bootstrap.min.css"  rel="stylesheet">
<link href="<%=path %>/static/css/list.css"  rel="stylesheet">
<link href="<%=path %>/static/css/basic.css"  rel="stylesheet">
<script type="text/javascript" src="<%=path %>/static/js/plugs/jquery/jquery.min.js"></script>
<body>
<jsp:include page="top.jsp"></jsp:include>
	<div style="width: 100%; height:100%; border: 1px solid red;">
		<jsp:include page="left.jsp"></jsp:include>
		<div style="width:100%; height: 100%; border: 1px solid blue;" id="content">
			<div id="list_NR" style="float: left;">
				<div class="loc">
					<h3>性别管理</h3>
				</div>

				<div class="list_con_table">
					<input type="hidden" value="" id="totalCountsHidden">
					<form action="" method="get" id="queryForm">
						<div class="search_table">
							<ul>
								<li class="Label_1_1">名称：&nbsp;</li>
								<li class="Label_2_2">
								<input class="form-control" type="text" name="name" value="" /></li>
								<li class="Label_2_2">
								<button class="button" onclick="">查询</button></li>
							</ul>
						</div>
					</form>
					<form action="" method="get" id="pageForm">
						<input type="hidden" name="currentPage" value="" id="currentPageHidden"> 
						<input type="hidden" name="pageSize" value="" id="pageSizeHidden"> 
						<input type="hidden" name="name" value="" />

					</form>
				</div>
				<button class="button" onclick="insertSex()" style="float:right;">新增</button>
				<table class="tableList" cellpadding="0" cellspacing="0">
					<tr>
						<td class="tdLabel_4" style="display: none">主键</td>
						<td class="tdLabel_4">编号</td>
						<td class="tdLabel_4">名称</td>
						<td class="tdLabel_4">编辑</td>
						<td class="tdLabel_4">删除</td>
					</tr>
					<tbody id="tbody">
						<c:forEach var="sex" items="${sexes}">
							<tr>
								<td class="tdLabel_4" style="display: none">${sex.id }</td>
								<td class='tdLabel_5'>${sex.no}</td>
								<td class='tdLabel_5'>${sex.name}</td>
								<td class='tdLabel_5'>
								<a onclick="updateSex(${sex.id})">
								<img src="<%=path %>/static/images/edit.png" style="height: 23px;margin-bottom: 8px;"/>
								</a></td>
								<td class='tdLabel_5'>
								<a onclick="deleteSex(${sex.id})">
								<img src="<%=path %>/static/images/del.png" style="height: 23px;margin-bottom: 8px;"/>
								</a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>


		</div>
	</div>
</body>

<script type="text/javascript">
	   function deleteSex(id){
		   $.ajax({
	            type: "POST",
	           url:"<%=basePath%>/basic/validateSexIsUse?id="+id,
	            success: function(data) {
	            	if (data.success==true) {
	            		 $.ajax({
	         	            type: "POST",
	         	           url:"<%=basePath%>/basic/deleteBasicNum?id="+id+"&tableName=sex",
	         	            success: function(data) {
	         	            	if (data.success==true) {
	         	            		location.href="<%=basePath%>";
	         	    			} else {
	         	    				alert("删除失败");
	         	    			}
	         	            }
	         	        }); 
	    			} else {
	    				alert("该性别已被引用不可删除");
	    			}
	            }
	        }); 
		   
	   }
	   
	   function insertSex(){
		    location.href="<%=basePath%>/basic/addBasicNumPage?tableName=sex"; 
	   }
	   
	   function updateSex(id){
		   location.href = "<%=basePath%>/basic/showBasicNum?tableName=sex"&id="+id;
	   }
	</script>
</html>
